
package nc.impl.hrppl.procancel.procancelhvo;

import java.util.Arrays;

import org.apache.commons.lang3.ArrayUtils;

import nc.bs.framework.common.NCLocator;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.SuperVO;
import nc.vo.pub.ISuperVO;
import nc.vo.pub.IVOMeta;
import nc.vo.pub.VOStatus;
import nc.vo.pubapp.pattern.model.meta.entity.bill.IBillMeta;
import nc.vo.trade.pub.HYBillVO;
import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
import nccloud.bs.excel.IXChangeContext;
import nccloud.bs.excel.plugin.AbstractImportProceeWithContext;
import nc.vo.hrppl.procancel.ProCancelBVO;
import nc.vo.hrppl.procancel.ProCancelCVO;
import nc.vo.hrppl.procancel.CGCancelCVO;
import nc.vo.hrppl.procancel.ProCancelHVO;
import nc.vo.hrppl.procancel.AggProCancelHVO;
import nc.itf.hrppl.procancel.procancelhvo.IProCancelHVOService;

public class AggProCancelHVOImportProcess extends AbstractImportProceeWithContext {
	
	@Override
	protected void processBillWithContext(Object vo, IXChangeContext changcontext) throws BusinessException {
		AggProCancelHVO targetVO = (AggProCancelHVO)vo;
		targetVO.getParentVO().setStatus(VOStatus.NEW);

		ProCancelBVO[] proCancelBVOs = (ProCancelBVO[])targetVO.getChildren(ProCancelBVO.class);
		if(proCancelBVOs!=null && proCancelBVOs.length>0){
			Arrays.stream(proCancelBVOs).forEach(subvo->{
				subvo.setStatus(VOStatus.NEW);
			});
		}
		CGCancelCVO[] cGCancelCVOs = (CGCancelCVO[])targetVO.getChildren(CGCancelCVO.class);
		if(cGCancelCVOs!=null && cGCancelCVOs.length>0){
			Arrays.stream(cGCancelCVOs).forEach(subvo->{
				subvo.setStatus(VOStatus.NEW);
			});
		}
		ProCancelCVO[] proCancelCVOs = (ProCancelCVO[])targetVO.getChildren(ProCancelCVO.class);
		if(proCancelCVOs!=null && proCancelCVOs.length>0){
			Arrays.stream(proCancelCVOs).forEach(subvo->{
				subvo.setStatus(VOStatus.NEW);
			});
		}
  		getService().initDefaultData(targetVO.getParentVO());
		getService().saveAggProCancelHVO(targetVO);
	}
	
	private IProCancelHVOService getService() {
		return NCLocator.getInstance().lookup(IProCancelHVOService.class);
	}

}
